const { DataTypes } = require('sequelize');
// const sequelize = require('@/db/seq');
const sequelize = require("@/db/seq");

const MomentComment = sequelize.define('moment_comment', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  moment_id: { type: DataTypes.INTEGER, allowNull: false },
  user_id: { type: DataTypes.INTEGER, allowNull: false },
  content: { type: DataTypes.TEXT, allowNull: false },
  reply_id: { type: DataTypes.INTEGER, allowNull: true, comment: '回复评论id' },
}, { freezeTableName: true });
// MomentComment.sync({ alter: true });

MomentComment.associate = (models) => {
  MomentComment.belongsTo(models.moment, { foreignKey: 'moment_id', as: 'moment' });
  MomentComment.belongsTo(models.blog_user, { foreignKey: 'user_id', as: 'commenter' });
  MomentComment.belongsTo(MomentComment, { foreignKey: 'reply_id', as: 'replyToComment' });
};
module.exports = MomentComment;